/**
 * @author liangxi
 * @since 2024/4/11
 */
#include "HasQuarterState.h"
#include "../GumballMachine.h"

void HasQuarterState::insertQuarter() {
    std::cout << "You can not insert another quarter\n";
}

void HasQuarterState::ejectQuarter() {
    std::cout << "Quarter returned\n";
    mGumballMachine->setState(mGumballMachine->getNoQuarterState());
}

void HasQuarterState::turnCrank() {
    std::cout << "You turned...\n";
    int winner = rand() % 10;
    if ((0 == winner) && (mGumballMachine->getMCount() > 1)) {
        mGumballMachine->setState(mGumballMachine->getWinnerState());
    } else {
        mGumballMachine->setState(mGumballMachine->getSoldState());
    }
}

void HasQuarterState::dispense() {
    std::cout << "No gumball dispensed\n";
}

GumballMachine *HasQuarterState::getMGumballMachine() const {
    return mGumballMachine;
}

void HasQuarterState::setMGumballMachine(GumballMachine *gumballMachine) {
    HasQuarterState::mGumballMachine = gumballMachine;
}